﻿using System;
using System.Collections.Generic;
using System.Text;
using SpeechLib;
using System.Threading;//这个引用是用来保存语音文件用的线程类

namespace SMS.BaseClass
{
    public static class Speech
    {
        #region 语音朗读
        /// <summary>
        /// 语音朗读
        /// </summary>
        /// <param name="str"></param>
        public static void SpeechString(string str)
        {
            if (SMS.Properties.Settings.Default.VOICE_OPEN)
            {
                // 参数设置
                SpeechVoiceSpeakFlags flag = SpeechVoiceSpeakFlags.SVSFlagsAsync;
                SpVoice voice = new SpVoice();
                // Win7默认库：单词女声
                voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
                // 语速
                voice.Rate = SMS.Properties.Settings.Default.VOICE_RATE;
                // 音量
                voice.Volume = SMS.Properties.Settings.Default.VOICE_VOLUME;
                // 朗读
                voice.Speak(ConvertNumToCn(str), flag);
                voice.WaitUntilDone(1000);
            }
        }
        #endregion 语音朗读

        #region 阿拉伯数字转汉字
        /// <summary>
        /// 阿拉伯数字转汉字
        /// </summary>
        /// <param name="str"></param>
        public static string ConvertNumToCn(string str)
        {
            str = str.Replace("0", "零");
            str = str.Replace("1", "一");
            str = str.Replace("2", "二");
            str = str.Replace("3", "三");
            str = str.Replace("4", "四");
            str = str.Replace("5", "五");
            str = str.Replace("6", "六");
            str = str.Replace("7", "七");
            str = str.Replace("8", "八");
            str = str.Replace("9", "九");

            return str;

        }
        #endregion 阿拉伯数字转汉字

    }
}
